﻿using CRL.Core;
using CRL.Data;
using CRL.Data.DBAccess;
using CRL.RedisProvider;
using CRL.Sqlite;
using CRL.Transaction;
using CRL.Transaction.DbStatus;
using System;

namespace transTest
{
    class Program
    {
        const string sqlLiteDb = "Data Source=d:\\sqlliteTest.db;";

        static void Main(string[] args)
        {
            var builder = DBConfigRegister.GetInstance();
            builder.UseSqlite();
            builder.RegisterDBAccessBuild(dbLocation =>
            {
                return new DBAccessBuild(DBType.SQLITE, sqlLiteDb);
            });
            var cb = new ConfigBuilder();
            cb.UseRedis("Server_204@127.0.0.1:6389");

            //TransConfig.RegisterTransInfoManage("test", () => new TransInfoManage());
            TransConfig.RegisterTransInfoManage("test", () => new MemoryTransInfoManage());

            var types = new Type[] { typeof(Program), typeof(TccTest), typeof(SagaTest) };
            ConsoleTest.DoCommand(types);
        }
        public static void testCustomStep()
        {
            var sagaControl = new SagaControl();
            sagaControl.Start(new TransOptions { Name = "testCustomStep", UseLog = true });
            sagaControl.Then(() =>
            {
                Console.WriteLine("commit1");
            }, () =>
            {
                Console.WriteLine("cancel1");
            }).Then(() =>
            {
                throw new Exception("22");
                Console.WriteLine("commit2");
            }, () =>
            {
                Console.WriteLine("cancel2");
            });
            sagaControl.Execute();
        }
    }

}
